//
//  ViewOne.m
//  Quartz
//
//  Created by thinkjoy on 2017/6/29.
//  Copyright © 2017年 杜瑞胜. All rights reserved.
//

#import "ViewOne.h"

@implementation ViewOne

- (void)drawRect:(CGRect)rect {
////    UIBezierPath* p = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0,0,100,50)];
////    UIBezierPath    * p =   [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0,0,200,200) byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(80, 0)];
//    
//    UIBezierPath    * p =   [UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 100) radius:80 startAngle:0 endAngle:M_PI_2 clockwise:NO];
//                             
//    
//    UIBezierPath * _p   =   [p bezierPathByReversingPath];
////    p.CGPath
//    [[UIColor whiteColor] setFill];
//    [_p fill];
    
//    UIColor *color = [UIColor redColor];
//    [color set]; //设置线条颜色
//    
//    UIBezierPath    * p =   [UIBezierPath bezierPath];
//    [p setLineWidth:5.f];
//    [p moveToPoint:CGPointMake(10, 10)];
//    [p addLineToPoint:CGPointMake(190, 10)];
//    [p addLineToPoint:CGPointMake(100, 190)];
//    [p closePath];
//    
//    [[UIColor whiteColor] setFill];
//    
//    [p fill];

    
//    [[UIColor redColor] set];
//    
//    UIBezierPath * p    =   [UIBezierPath bezierPath];
//    [p moveToPoint:CGPointMake(10, 180)];
//    [p addQuadCurveToPoint:CGPointMake(190, 180) controlPoint:CGPointMake(10, 10)];
//    [p stroke];
    
    
//    [[UIColor redColor] set];
//    
//    
//    UIBezierPath * p    =   [UIBezierPath bezierPath];
//    [p moveToPoint:CGPointMake(10, 100)];
//    [p addLineToPoint:CGPointMake(100, 0)];
//    [p addLineToPoint:CGPointMake(20, 100)];
//    [p moveToPoint:CGPointMake(20, 100)];
//    [p addCurveToPoint:CGPointMake(190, 100) controlPoint1:CGPointMake(55, 50) controlPoint2:CGPointMake(135, 150)];
//    
//    [p addLineToPoint:CGPointMake(0, 0)];
//    
//    [p addArcWithCenter:CGPointMake(100, 100) radius:80 startAngle:3*M_PI_2 endAngle:2*M_PI clockwise:YES];
////    [p stroke];
//
//    
//    UIBezierPath * lineP    =   [UIBezierPath bezierPath];
//    [lineP moveToPoint:CGPointMake(190, 100)];
//    [lineP addLineToPoint:CGPointMake(190, 190)];
//    [lineP stroke];
//    
//    
////    [p appendPath:lineP];
//    
//    [p stroke];
    
    
    CGFloat view_W  =   2/2.2 * MIN(CGRectGetWidth(rect), CGRectGetHeight(rect));
    CGFloat view_H  =   view_W;
    CGFloat view_X  =   (CGRectGetWidth(rect)-view_W)/2.f;
    CGFloat view_Y  =   (CGRectGetHeight(rect)-view_H)/2.f;
    CGFloat view_C_X    =   CGRectGetWidth(rect)/2;
    CGFloat view_C_Y    =   CGRectGetHeight(rect)/2;
    
    [[UIColor redColor] set];
    UIBezierPath    * ovalP =   [UIBezierPath bezierPathWithOvalInRect:CGRectMake(view_X, view_Y, view_W, view_H)];
    [ovalP stroke];
    
    for (int i=0; i<12*5; i++) {
        CGFloat outRadiu    =   view_W/2.f;
        CGPoint outPoint    =   CGPointMake(view_C_X+outRadiu*cos(i*(M_PI_2/15.f)), view_C_Y+outRadiu*sin(i*(M_PI_2/15.f)));
        
        CGFloat inLongRadiu    =   view_W/2.f-10*(view_W/220.f);
        CGPoint inLongPoint    =   CGPointMake(view_C_X+inLongRadiu*cos(i*(M_PI_2/15.f)), view_C_Y+inLongRadiu*sin(i*(M_PI_2/15.f)));
        
        CGFloat inShortRadiu    =   view_W/2.f-10*(view_W/220.f)*0.618;
        CGPoint inShortPoint    =   CGPointMake(view_C_X+inShortRadiu*cos(i*(M_PI_2/15.f)), view_C_Y+inShortRadiu*sin(i*(M_PI_2/15.f)));
        
        [[UIColor redColor] set];
        UIBezierPath * lineP    =   [UIBezierPath bezierPath];
        [lineP moveToPoint:outPoint];
        
        if (i%5==0) {
            [lineP addLineToPoint:inLongPoint];
        }else{
            [lineP addLineToPoint:inShortPoint];
        }
        
        [lineP stroke];
    }
    
    
}

@end
